package com.app.web.merchant;

import com.app.utils.base.j2se.Common;
import com.app.utils.base.j2se.Convert;
import com.app.utils.base.j2se.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * Description
 * Created by 王伟
 * Date create on 21:09 2019/11/25.
 */
@Service
public class MerchantService {
    @Autowired
    private MerchantDao merchantDao;

    /**
     * 根据商家ID查询基本信息
     * @param id
     * @return
     */
    public Merchant merchant(int id){
        Map<String,Object> param = new HashMap<>();
        param.put("id",id);
        List<Merchant> merchants = merchantDao.merchantList(param);
        return Common.isNotEmpty(merchants)?merchants.get(0):null;
    }

    /**
     * 查询商家列表
     * @param name  商家名
     * @param is_recommend  是否严选
     * @param page  分页
     * @return
     */
    public List<Merchant> merchantList(String name, int is_recommend, int page){
        Map<String,Object> param = new HashMap<>();
        param.put("name",name);
        param.put("is_recommend",is_recommend);

        param.put("page",page);
        param.put("startSize",(page-1)*20);
        param.put("endSize",20);
        return merchantDao.merchantList(param);
    }

    /**
     * 根据商家ID查询商家的资质图
     * @param id
     * @return
     */
//    @RedisCache(timeOut = 3600)
    public List<MerchantPics> merchantPics(int id){
        return merchantDao.merchantPics(id);
    }

    /**
     * 根据多个商家ID查询商家的资质图
     * @param list
     * @return
     */
//    @RedisCache(timeOut = 3600)
    public List<MerchantPics> merchantPicsList(List<Integer> list){
        return merchantDao.merchantPicsList(list);
    }

    /**
     * 根据多个医院ID查询医院信息
     * @param list
     * @return
     */
    public Map<Integer, Merchant> merchantCollectionList(List<Integer> list){
        List<Merchant> listHospital =  merchantDao.merchantCollectionList(list);

        return listHospital.stream().collect(Collectors.toMap(Merchant::getId,Function.identity()));
    }

}
